package org.flint92.springboot.mbean.jmx.controller;

import org.apache.commons.lang3.StringUtils;
import org.flint92.springboot.mbean.jmx.bean.SimpleBean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author flint92
 */
@RestController
public class JmxController {

    @Resource
    private SimpleBean simpleBean;

    @GetMapping("/jmx/simple-bean")
    public SimpleBean getSimpleBean(@RequestParam(required = false) Long id,
                                    @RequestParam(required = false) String name,
                                    @RequestParam(required = false) Integer value) {
        if (Objects.nonNull(id)) {
            simpleBean.setId(id);
        }

        if (StringUtils.isNoneBlank(name)) {
            simpleBean.setName(name);
        }

        if (Objects.nonNull(value)) {
            simpleBean.setValue(value);
        }

        return simpleBean;
    }

}
